package com.yogee.topseller.fragment.productdetail;

import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.core.base.*;
import com.yogee.topseller.R;
import com.yogee.topseller.bean.ProductInfoBean;
import com.yogee.topseller.view.MyScrollView;
import com.yogee.topseller.view.PublicStaticClass;
import com.yogee.topseller.view.PullUpToLoadMore;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by zwj on 2017/12/7.
 */

public class BaseInfoFragment extends BaseFragment {

    @BindView(R.id.product_subject_tv)
    TextView product_subject_tv;
    @BindView(R.id.product_highlights_light_tv)
    TextView product_highlights_light_tv;
    @BindView(R.id.product_cuoshi_tv)
    TextView product_cuoshi_tv;
    @BindView(R.id.product_use_tv)
    TextView product_use_tv;
    @BindView(R.id.product_laiyuan_tv)
    TextView product_laiyuan_tv;
    @BindView(R.id.oneScrollview)
    MyScrollView oneScrollView;


    // 内容为空时需要隐藏部分
    @BindView(R.id.ll_cpld)
    LinearLayout ll_cpld;
    @BindView(R.id.ll_fkcs)
    LinearLayout ll_fkcs;
    @BindView(R.id.ll_zjyt)
    LinearLayout ll_zjyt;
    @BindView(R.id.ll_hkly)
    LinearLayout ll_hkly;
    @BindView(R.id.ll_xl)
    LinearLayout ll_xl;
    @BindView(R.id.ll_fkcs_title)
    LinearLayout ll_fkcs_title;
    @BindView(R.id.details_high_ll)
    LinearLayout details_high_ll;
    @BindView(R.id.ll_hkly_title)
    LinearLayout ll_hkly_title;
    @BindView(R.id.ll_zjyt_title)
    LinearLayout ll_zjyt_title;
    Unbinder unbinder1;
    private ProductInfoBean beans;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_product_baseinfo;
    }

    @Override
    protected void initView() {

        beans = (ProductInfoBean) getArguments().getSerializable("baseInfo");
        product_subject_tv.setText(beans.getSubject());

        if("".equals(beans.getLight())){
            ll_cpld.setVisibility(View.GONE);
            details_high_ll.setVisibility(View.GONE);
//            product_highlights_light_tv.setText("暂无数据");
        }else
            product_highlights_light_tv.setText(Html.fromHtml(beans.getLight()));

        if("".equals(beans.getCuoshi())){
//            product_cuoshi_tv.setText("暂无数据");
            ll_fkcs_title.setVisibility(View.GONE);
            ll_fkcs.setVisibility(View.GONE);
        }else
            product_cuoshi_tv.setText(Html.fromHtml(beans.getCuoshi()));
        if("".equals(beans.getFundUse())){
//            product_use_tv.setText("暂无数据");
            ll_zjyt.setVisibility(View.GONE);
            ll_zjyt_title.setVisibility(View.GONE);
        } else
            product_use_tv.setText(Html.fromHtml(beans.getFundUse()));
        //还款来源
        if ("".equals(beans.getLaiyuan())) {
            ll_hkly_title.setVisibility(View.GONE);
            ll_hkly.setVisibility(View.GONE);
            ll_hkly.setVisibility(View.GONE);
//            product_laiyuan_tv.setText("暂无数据");
        } else {
            product_laiyuan_tv.setText(Html.fromHtml(beans.getLaiyuan()));
        }

        oneScrollView.setScrollListener(new MyScrollView.ScrollListener() {
            @Override
            public void onScrollToBottom() {

            }

            @Override
            public void onScrollToTop() {

            }

            @Override
            public void onScroll(int scrollY) {
                if (scrollY == 0) {
                    PublicStaticClass.IsTop = true;
                } else {
                    PublicStaticClass.IsTop = false;
                }
            }

            @Override
            public void notBottom() {

            }

        });

        ll_xl.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                ((PullUpToLoadMore)oneScrollView.getParent().getParent().getParent().getParent()).scrollToTop();
            }
        });
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder1 = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder1.unbind();
    }

    @Override
    public String getTitle() {
        return "基本信息";
    }
}
